<?php
    /**
     * aheadWorks Co.
     *
     * NOTICE OF LICENSE
     *
     * This source file is subject to the EULA
     * that is bundled with this package in the file LICENSE.txt.
     * It is also available through the world-wide-web at this URL:
     * http://ecommerce.aheadworks.com/LICENSE-M1.txt
     *
     * @category   AW
     * @package    AW_Vidtest
     * @copyright  Copyright (c) 2010 aheadWorks Co. (http://www.aheadworks.com)
     * @license    http://ecommerce.aheadworks.com/LICENSE-M1.txt
     */
/**
 * This is template for AW_Vidtest_Block_Product_View
 */
?>
<?php if ($this->canShow()): ?>
<?php
    $firstId = null;

    $this->addHandleForCurrentLayout();
    $this->initRatioThumbsToLayout();

    # Set up pixels for scroll per one
    $this->setPixelsScroll('138');
?>
<div id="video-uploadform-block" class="box-tabs"  <?php if(!$this->hasVideos()):?>style="display:none"<?php endif;?>><div class="box-tabs-b"> 
<div class="aw-vidtest-collateral-box collateral-box<?php if (Mage::helper('vidtest')->checkVersion('1.4.0.0')) { echo ' box-collateral'; } ?>"<?php if (Mage::helper('vidtest')->checkVersion('1.4.0.0')) { echo ' id="for_1400"'; } ?>>
   
        <div class="head">
            <h4 class="title"><?php echo $this->getSectionTitle(); ?> 
             <?php if ($this->canUpload()): ?>
                 <span class="add-own-video-button"><a href="#" onclick="$('uploadform-content').toggle(); return false;"><?php echo $this->__('Upload Your Video'); ?></a></span>
            <?php else:?>
                  <span class="add-own-image-button"><a href="<?php echo $this->getUrl('customer/account/login')?>"><?php echo $this->__('Upload Your Video'); ?></a></span>  
            <?php endif; ?></h2>
           </h4>
           
        </div>
 
    <?php if (true): ?>
    <div id="vidtest-player" class="aw-vidtest-player">
        <?php if ($this->canUpload()): ?>
        <div id="uploadform-content" style="display: none;">
            <div>
            <?php echo $this->getForm(); ?>
            </div>
        </div>
        <?php endif; ?>
        <div id="player-content" style="display: block;">
            <div>
            <?php //echo $this->getPlayer(); ?>
            </div>
        </div>
    </div>
    <?php if ($this->hasVideos()): ?>
    <div class="aw-vidtest-details">
        <div class="aw-vidtest-description<?php if (!$this->showRate()) { echo ' no-rating'; } ?>" id="details-content">

            
        </div>
        <?php if ($this->showRate()): ?>
        <div class="aw-vidtest-rates" id="rate-content">
            <div class="rate-box" id="aw-rate-box" onmouseout="vidtest.mouseOut(this);">
                <div class="rate-selector">
                    <a href="#" onmouseover="vidtest.mouseMove(1);" onclick="vidtest.mouseClick(1); return false;"></a>
                    <a href="#" onmouseover="vidtest.mouseMove(2);" onclick="vidtest.mouseClick(2); return false;"></a>
                    <a href="#" onmouseover="vidtest.mouseMove(3);" onclick="vidtest.mouseClick(3); return false;"></a>
                    <a href="#" onmouseover="vidtest.mouseMove(4);" onclick="vidtest.mouseClick(4); return false;"></a>
                    <a href="#" onmouseover="vidtest.mouseMove(5);" onclick="vidtest.mouseClick(5); return false;"></a>
                </div>
                <div class="rate" id="aw-rate-indicator" style="width: 50%;">

                </div>
            </div>
            <div class="notice" id="aw-rate-notice"><?php echo $this->__('Thanks for voting'); ?></div>
            <div class="notice" id="aw-rate-loader"><?php echo $this->__('Voting...'); ?></div>
        </div>
        <?php endif; ?>
    </div><!--aw-vidtest-details-->
    
    <div class="aw-vidtest-scroll-box">
        <div class="aw-vidtest-scroll-panel">
            <div class="counter">
                <span><?php echo $this->__('%s Videos', count($this->getCollection())) ?></span>
            </div>
            <div class="buttons">
            <?php if ($this->showButtons()): ?>
                <?php foreach($this->getButtons() as $button): ?>
                <div class="page-button"><a class="<?php if ($button->getFirst()) { echo ' active first'; } if ($button->getLast()) { echo 'last'; } ?>" href="#" onclick="vidtest.scrollToAnchor('page-button-<?php echo $button->getId(); ?>', '<?php echo $button->getLeft(); ?>'); return false;" id="page-button-<?php echo $button->getId(); ?>"><span><?php echo $button->getNum(); ?></span></a></div>
                <?php endforeach; ?>
            <?php endif; ?>
            </div>
        </div>
        <div class="aw-vidtest-scroller">
        <a class="scroll-button<?php if (!$this->showButtons()){ echo ' disabled'; } ?>" id="sbt-left" href="#" onclick="vidtest.scrollLeft(this); return false;"></a>
        <div id="aw-vidtest-scroll-frame-id" class="aw-vidtest-scroll-frame">
            <div class="aw-vidtest-scroll-line" id="scroll-line">
            <?php foreach ($this->getCollection() as $item): ?>
                <?php $firstId = $firstId ? $firstId : $item->getApiVideoId(); ?>

                <div class="aw-vidtest-videoitem" id="<?php echo $item->getApiVideoId(); ?>">
                    
                    <div class="border">
                        <a href="#" onclick="vidtest.playVideo('<?php echo $item->getApiVideoId(); ?>'); return false;">
                            <img alt="thumbnail"  src="<?php echo $item->getThumbnail(); ?>" class="image120" />
                        </a>
                    </div>
                    <span class="aw-vidtest-video-time"><span><?php echo $item->getTime(); ?></span></span>
                    
                    <div class="title">
                        <a href="#" onclick="vidtest.playVideo('<?php echo $item->getApiVideoId(); ?>'); return false;"><?php echo $item->getTitle(); ?></a>
                        <br/>
                        <?php echo $item->getAuthorName(); ?>
                    </div>
                </div>
            <?php endforeach; ?>
            </div>
            </div>
        <a class="scroll-button<?php if (!$this->showButtons()){ echo ' disabled'; } ?>" id="sbt-right" href="#" onclick="vidtest.scrollRight(this); return false;"></a>
        </div>
    
    </div><!--aw-vidtest-scroll-box-->
  
    <?php else: ?>
         <div class="notice-msg"><?php echo $this->__('No video uploaded yet'); ?></div>
    <?php endif; ?>
    <?php endif; ?>
</div>

<script type="text/javascript">
  var vidtest = new AWVidtest($('vidtest-player').getWidth(), $('vidtest-player').getHeight(), '<?php echo $this->getPixelsScroll(); ?>', '<?php echo $this->getThumbnailCount(); ?>', '<?php echo count($this->getCollection()); ?>');
  <?php if ($this->hasVideos()): ?>
      vidtest.detailTemplate = '<a href="{{v_url}}" target="_blank">{{title}}</a> &mdash; {{date}}<br>' +
          '{{details}}';
      vidtest.ajaxUrl = '<?php echo $this->getAjaxUrl(); ?>';

      <?php foreach ($this->getCollection() as $item): ?>
      vidtest.addVideo("<?php echo $item->getApiVideoId(); ?>",
                        "<?php echo $item->getApiVideoUrl(); ?>",
                        "<?php echo Mage::getSingleton('vidtest/connector')->getApiModel($item->getApiCode())->getVideoUrl($item->getApiVideoId()); ?>",
                        "<?php echo $item->getRate(); ?>",
                        "<?php echo $this->getCanRate($item->getId()); ?>",                        
                        "<?php echo $item->getTitle(); ?>",
                        "<?php echo $this->prepareToDisplay($item->getComment()); ?>",
                        "<?php echo $item->getPublicDate(); ?>",
                        "<?php echo $item->getId(); ?>");
      <?php endforeach; ?>
          vidtest.playVideo('<?php echo $firstId; ?>');
  <?php else: ?>
      //vidtest.toogleForm();
  <?php endif; ?>
</script>
</div></div><?php endif; ?>
